package com.we823.project.repository.dao.repo;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.we823.project.model.repo.CategoryModel;
import com.we823.project.model.repo.MaterialModel;

@Repository("materialRepository")
public interface MaterialRepository extends JpaRepository<MaterialModel, Integer> {

	List<MaterialModel> findByCategory(CategoryModel categoryModel);

	Page<MaterialModel> findByCategory(CategoryModel categoryModel, Pageable pageable);

	Page<MaterialModel> findByFullnameContaining(String fullname, Pageable pageable);

	MaterialModel findByFullnameAndColor(String modelString, String color);

	MaterialModel findByModelAndColor(String model, String color);

	MaterialModel findByCode(String code);

	List<MaterialModel> findByCodeIn(List<String> materialCodeList);

	Page<MaterialModel> findByCodeContaining(String queryString, Pageable pageable);

	List<MaterialModel> findByCategoryIn(List<CategoryModel> categoryModels);

	@Query("from MaterialModel m where (m.fullname=?1 or m.specification=?2) and color=?3")
	@Transactional
	MaterialModel findByFullnameOrSpecificationAndColor(String fullname,
			String specification, String color);

}
